package com.zggk.lzz.dtfdbridge;

import android.app.Activity;

import com.alibaba.fastjson.JSON;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.bridgetmx.BridgeMxBean;
import com.zggk.lzz.callback.StringDialogCallback;
import com.zggk.lzz.mvp.BasePresenterImpl;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class DtfdBridgePresenter extends BasePresenterImpl<DtfdBridgeContract.View> implements DtfdBridgeContract.Presenter{
    @Override
    public void getData(Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER5+"proj/apiserver/apisno/ncglFindBridge")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .params("orgId",MyApplication.spUtils.getString("OrgId"))
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        DtfbBean dtfbBean = JSON.parseObject(response.body(),DtfbBean.class);
                        if (mView == null)
                            return;
                        if (dtfbBean.getMsg().equals("查询成功")){
                            mView.getDatas(dtfbBean);
                        }else {
                            mView.onRequestError(dtfbBean.getMsg());
                        }
                    }
                });
    }
    @Override
    public void getData2(String id, Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER5 + "proj/apiserver/apisno/ncglFindBridgeMessage")
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token", ""))
                .params("bridgeId", id)
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        BridgeMxBean bridgeMxBean = JSON.parseObject(response.body(),BridgeMxBean.class);
                        if (mView == null)
                            return;
                        mView.getDatas2(bridgeMxBean);
                    }
                });
    }
}
